﻿#include <QApplication>
#include <QSharedMemory>

#include "globaldata.h"
#include "Window/mygui.h"
#include "Window/mainwindow.h"

int main(int argc, char *argv[])
{
    QSharedMemory shared_memory;

    shared_memory.setKey(QString("TSRIESystem"));

    if(shared_memory.attach()) return 0;
    if(!shared_memory.create(1)) return 0;

    QApplication a(argc, argv);

    MyGUI::SetFont();
    MyGUI::SetStyle(":/qss/blue.qss");

    int exec = 0;
    auto globalData = GlobalData::GetInstance();

    try{
        globalData->Init();
        MyLog::Info("系统启动");

        MainWindow w;
        w.setWindowTitle("江西省吉安802台");
        w.show();
        //MyHelper::FormInCenter(&w);

        exec = a.exec();

        globalData->sqlBase->StopAllAlarm();
        MyLog::Info("系统关闭");

    }catch (Error e){
        MyLog::Error(e.strError);
    }catch (QString strError){
        MyLog::Error(strError);
    }catch (...){
        MyLog::Info("系统异常关闭 未知错误");
    }
    return exec;
}
